//用参数（TweenParams）控制动画播放方式
using DG.Tweening;
using UnityEngine;

public class DOTweenParam : MonoBehaviour
{
    public Transform mCube1;
    public AnimationCurve mCurve;
    
    void Start()
    {
        TweenParams param = new TweenParams();
        param.SetLoops(-1);
        param.SetAutoKill(); //自动销毁动画，反正会缓存动画
        param.SetDelay(3);  //3秒后执行
        param.SetRecyclable(true);  //是否可回收
        transform.DOMoveX(5, 1).SetAs(param).From();   //目标点运动回来
        transform.DOMoveX(5, 1).SetSpeedBased(true);   //以速度为基准
        transform.DOMoveX(5, 1).SetId("move");        //用id控制
        transform.DOMoveX(5, 1).SetRelative(true);   //在某个基础上进行叠加
        transform.DOMoveX(5, 1).SetUpdate(UpdateType.Normal);   //进行帧动画
    }

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.A))
        {
            mCube1.DOLocalRotate(Vector3.up * 360, 2, RotateMode.FastBeyond360)
                .SetEase(Ease.Linear).SetLoops(-1, LoopType.Incremental);
        }
        else if (Input.GetKeyDown(KeyCode.B))
        {
            mCube1.DOLocalRotate(Vector3.up * 360, 2, RotateMode.FastBeyond360)
                .SetEase(Ease.Flash, 3, 3);
        }
        else if (Input.GetKeyDown(KeyCode.D))
        {
            mCube1.DOMoveX(5, 1).SetEase(mCurve);
        }
        else if (Input.GetKeyDown(KeyCode.F))
        {
            mCube1.DOMoveX(5, 1).SetEase(EaceFun);
        }
    }

    private float EaceFun(float time, float duration, float overshootoramplitude, float period)
    {
        return time / duration;
    }
}
